//
//  ZYGuideView.m
//  Tourism
//
//  Created by 张亚 on 16/1/23.
//  Copyright © 2016年 zhikuiyu. All rights reserved.
//

#import "ZYGuideView.h"


#import "ZYStatuse.h"
#import "ZYStatuserCell.h"
#import "ZYStatusFrame.h"




@interface ZYGuideView ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) NSArray * statusFrames;

@end

@implementation ZYGuideView

////////////////////////////////////
- (NSArray *)statusFrames{
    if (_statusFrames == nil) {
        NSString * path = [[NSBundle mainBundle] pathForResource:@"statuses.plist" ofType:nil];
        NSArray * dictArray = [NSArray arrayWithContentsOfFile:path];
        NSMutableArray * statusFrameArray = [NSMutableArray array];
        for (NSDictionary * dict in dictArray) {
            ZYStatuse * status = [ZYStatuse statuseWithDict:dict];
            ZYStatusFrame * statusFrame = [[ZYStatusFrame alloc]init];
            statusFrame.status = status;
            [statusFrameArray addObject:statusFrame];
        }
        _statusFrames = statusFrameArray;
    }
    return _statusFrames;
}


////////////////////////////////////


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor orangeColor];
        
        [self createdTableView];
    }
    return self;
}

#pragma mark --- 
- (void)createdTableView{
    UITableView * tabView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height) style:UITableViewStylePlain];
    tabView.delegate = self;
    tabView.dataSource = self;
    [self addSubview:tabView];
}
//行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.statusFrames.count;
}
//行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    //去每一行的内容高度
    ZYStatusFrame * statusFrame = self.statusFrames[indexPath.row];
    //拿Cell内部的子控件
    NSLog(@"%lf",statusFrame.cellHeight);
    return statusFrame.cellHeight;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    ZYStatuserCell * cell = [ZYStatuserCell cellWithTableView:tableView];
    
    cell.statusFrame = self.statusFrames[indexPath.row];
    return cell;
}

@end
